#!/usr/bin/python
# coding: utf-8

import logging.handlers
# from logging import *
# from datetime import *
import logging

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

rht = logging.handlers.TimedRotatingFileHandler("reindex_out.log", 'D')
fmt = logging.Formatter("%(asctime)s %(pathname)s %(filename)s %(funcName)s %(lineno)s \
      %(levelname)s - %(message)s", "%Y-%m-%d %H:%M:%S")
rht.setFormatter(fmt)
logger.addHandler(rht)

# debug = logger.debug
# info = logger.info
# warning = logger.warning
# error = logger.error
# critical = logger.critical
log = logger


import json


class Student(object):
    def __init__(self, name, age, score, reward):
        self.name = name
        self.age = age
        self.score = score
        self.reward = reward


s = Student('Bob', 20, 88, ["三好学生", "优秀团干", "最佳辩手"])
print(json.dumps(obj=s.__dict__, ensure_ascii=False))


class Student(object):
    def __init__(self, name, age, score, reward):
        self.name = name
        self.age = age
        self.score = score
        self.reward = reward

    def info(self):
        print(self.name, self.age, self.score)


def get_object_hook(obj_class):
    def object_hook(dc):
        return obj_class(**dc)
    return object_hook


json_str = '{"name": "Bob", "age": 20, "score": 88, "reward": ["三好学生", "优秀团干", "最佳辩手"]}'
# dc = json.loads(json_str)
student = json.loads(json_str, object_hook=get_object_hook(Student))
print(type(student))
print(student.name)
from bdtime import show_json
show_json(student.__dict__)
student.info()


def test_log_error():
    import traceback

    try:
        print(123 / 0)  # 放主要代码
    except Exception as e:

        logging.error("Main program error:")
        logging.error(e)
        logging.error(traceback.format_exc())


if __name__ == '__main__':
    pass
